﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UofCASE.AgileProductLinerDSL.Confeaturator.Model;
using UofCASE.AgileProductLinerDSL.Confeaturator;

namespace APLDTests
{
    [TestClass]
    [Ignore]
    public class ConfeatureatorCheckTest
    {
        FeatureNode root, alpha, beta, delta, gamma;

        [TestInitialize]
        public void setup()
        {
            UpdateableUI ignorantUI = new IgnorantUpdateableUI();

            gamma = new FeatureNode(null);
            gamma.UINode = ignorantUI;
            
            delta = new FeatureNode(null);
            delta.UINode = ignorantUI;
            
            beta = new FeatureNode(null);
            beta.UINode = ignorantUI;
            beta.requiredBy.Add(delta);
            beta.requiredBy.Add(gamma);
                delta.required.Add(beta);
                gamma.required.Add(beta);

            alpha = new FeatureNode(null);
            alpha.UINode = ignorantUI;
            alpha.excludes.Add(delta);
                delta.excludedBy.Add(alpha);

            root = new FeatureNode(null);
            root.UINode = ignorantUI;
            root.requiredBy.Add(alpha);
            root.requiredBy.Add(beta);
                alpha.required.Add(root);
                beta.required.Add(root);

            beta.Check();

            Assert.IsTrue(root.IsChecked);
            Assert.IsTrue(root.locked());
            Assert.AreEqual(FeatureModelNodeKind.Root, root.Kind);
            
            Assert.IsFalse(alpha.IsChecked);
            Assert.IsFalse(alpha.locked()); 
            Assert.AreEqual(FeatureModelNodeKind.Optional, alpha.Kind);

            Assert.IsTrue(beta.IsChecked);
            Assert.IsFalse(beta.locked()); 
            Assert.AreEqual(FeatureModelNodeKind.Optional, beta.Kind);

            Assert.IsFalse(delta.IsChecked);
            Assert.IsFalse(delta.locked()); 
            Assert.AreEqual(FeatureModelNodeKind.Optional, delta.Kind);

            Assert.IsFalse(gamma.IsChecked);
            Assert.IsFalse(gamma.locked()); 
            Assert.AreEqual(FeatureModelNodeKind.Optional, gamma.Kind);
        }


        [TestMethod]
        public void SelectingAFeatureLocksAllExcludedFeatures()
        {
            alpha.Check();
            Assert.IsTrue(alpha.IsChecked);
            Assert.IsFalse(alpha.locked());

            Assert.IsFalse(gamma.IsChecked);
            Assert.IsTrue(gamma.locked()); 
        }

        [TestMethod]
        public void SelectingAFeatureLocksAllFeaturesThatWouldExcludeIt()
        {
            gamma.Check();
            Assert.IsTrue(gamma.IsChecked);
            Assert.IsFalse(gamma.locked());

            Assert.IsFalse(alpha.IsChecked);
            Assert.IsTrue(alpha.locked());
        }

        [TestMethod]
        public void SelectingAFeatureLocksAllFeaturesThatAreRequiredByIt()
        {
            gamma.Check();
            Assert.IsTrue(gamma.IsChecked);
            Assert.IsFalse(gamma.locked());

            Assert.IsTrue(beta.IsChecked);
            Assert.IsTrue(beta.locked());
        }

        [TestMethod]
        public void UnselectingAFeatureLocksItsdependents()
        {
            beta.UnCheck();
            Assert.IsFalse(beta.IsChecked);
            Assert.IsFalse(beta.locked());

            Assert.IsFalse(gamma.IsChecked);
            Assert.IsTrue(gamma.locked());

            Assert.IsFalse(delta.IsChecked);
            Assert.IsTrue(delta.locked());
        }

        [TestMethod]
        public void LockedFeaturesCanNotBeUnChecked()
        {
            root.UnCheck();
            Assert.IsTrue(root.IsChecked);
            Assert.IsTrue(root.locked());
        }
    }
}
